<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>业绩审核</title>
    #include("common/header.html")
    <link rel="stylesheet" href="/admin/css/table.css"/>
</head>

<body>
<div class="admin-main">

    <blockquote class="layui-elem-quote">
        <a href="javascript:excel();" class="layui-btn layui-btn-small">
            <i class="layui-icon">&#xe608;</i> 添加产品
        </a>
    </blockquote>
    <fieldset class="layui-elem-field">
        <legend>产品列表</legend>
        <div class="layui-field-box layui-form">
            <table class="layui-table admin-table">
                <thead>
                <tr>
                    <th>姓名</th>
                    <th>身份证</th>
                    <th>电话</th>
                    <th>类型</th>
                    <th>金额(万元)</th>
                    <th>贷款时间</th>
                    <th>支行</th>
                    <th>地区</th>
                    <th>客户经理</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="pager">
                </tbody>
            </table>
        </div>
    </fieldset>
    <!--<div class="admin-table-page">-->
    <div class="page-table-box" id="page" style=" width:1000px; margin:0 auto; margin-top:100px;"></div>
    <!--</div>-->
</div>
</body>

<script type="text/javascript">

    $(function () {
        pageList(1);
    });

    function pageList(pageNum) {

        $.ajax({
            url: "/admin/business/",
            type: "post",
            dataType: "json",
            data: {"pageNum": pageNum, "pageSize": window.page.pageSize},
            success: function (r) {

                console.log(r);

                if (r.code == -1) {
                    return;
                }

                page(pageNum, r.data.total);

                $("#pager").html("");

                var str = "";

                $.each(r.data.list, function (n, value) {
                    str += '<tr>';
                    str += '<td>' + value.name + '</td>';
                    str += '<td>' + value.idCard + '</td>';
                    str += '<td>' + value.mobile + '</td>';
                    str += '<td>' + value.product + '</td>';
                    str += '<td>' + value.money + '</td>';
                    str += '<td>' + value.loanTime + '</td>';
                    str += '<td>' + value.area + '</td>';
                    str += '<td>' + value.addr + '</td>';
                    str += '<td>' + value.manager + '</td>';
                    str += '<td>';
                    str += '<a onclick="ok(' + value.id + ','+value.uid+')" class="layui-btn layui-btn-normal layui-btn-mini">同意</a>';
                    str += '<a onclick="no(' + value.id + ')" class="layui-btn layui-btn-danger layui-btn-mini">驳回</a>';
                    str += '</td>';
                    str += '</tr>';
                });

                $("#pager").html(str);
            }
        });
    }


    var layer;
    layui.use('layer', function () {
        layer = layui.layer;
    });



    function ok(id,uid) {

        //询问框
        layer.confirm('确定删除?', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $.ajax({
                url: "/admin/business/ok",
                type: "put",
                dataType: "json",
                data: {"id":id},
                success: function (r) {
                    console.log(r);

                    if(r.code == -1){
                        layer.msg(r.msg);
                        return;
                    }
                    layer.close(index);
                    layer.msg('修改成功!',{time:1500}, function(){
                        location.reload();
                    });
                }
            });
        });

//        layer.open({
//            type: 2,
//            title: '同意审批',
//            shadeClose: true,
//            shade: false,
//            zIndex: 99999999,
//            maxmin: true, //开启最大化最小化按钮
//            area: ['600px', '220px'],
//            content: '${ctx}/business/ok',
//            data: {"id":id},
//            btn: ['确定', '取消'],
//            yes: function (index, layero) {
//
//                var body = layer.getChildFrame('body',index);
//                var validate = body.find("#validate").validator();
//                var integral = body.find("#integral").val();
//
//                if(!validate.check()){return;}
//
//                $.ajax({
//                    url: "${ctx}/business/ok",
//                    type: "put",
//                    dataType: "json",
//                    data: {"id":id,"uid":uid,"integral": integral},
//                    success: function (r) {
//                        console.log(r);
//
//                        if(r.code == -1){
//                            layer.msg(r.msg);
//                            return;
//                        }
//                        layer.close(index);
//                        layer.msg('修改成功!',{time:1500}, function(){
//                            location.reload();
//                        });
//                    }
//                });
//
//            }
//        });
    }

    function no(id) {
        layer.open({
            type: 2,
            title: '同意审批',
            shadeClose: true,
            shade: false,
            zIndex: 99999999,
            maxmin: true, //开启最大化最小化按钮
            area: ['600px', '220px'],
            content: '/admin/business/no',
            data: {"id":id},
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                var body = layer.getChildFrame('body',index);
                var validate = body.find("#validate").validator();
                var because = body.find("#because").val();

                if(!validate.check()){return;}

                $.ajax({
                    url: "/admin/business/no",
                    type: "put",
                    dataType: "json",
                    data: {"id":id,"because": because},
                    success: function (r) {
                        console.log(r);

                        if(r.code == -1){
                            layer.msg(r.msg);
                            return;
                        }
                        layer.close(index);
                        layer.msg('修改成功!',{time:1500}, function(){
                            location.reload();
                        });
                    }
                });

            }
        });
    }
    
    function excel() {
        layer.open({
            type: 2,
            title: '导出Excel',
            shadeClose: true,
            shade: false,
            zIndex: 99999999,
            maxmin: true, //开启最大化最小化按钮
            area: ['600px', '400px'],
            content: '/admin/business/export',
            btn: ['确定导出', '取消'],
            yes: function (index, layero) {

                var body = layer.getChildFrame('body',index);
                var validate = body.find("#validate").validator();
                if(!validate.check()){return;}

                var start = body.find("#starttime").val();
                var end = body.find("#endtime").val();
                layer.close(index);
                location.href="/admin/business/excel?start="+start+"&end="+end;
            }
        });
    }

</script>

</html>